﻿using System;
using System.Collections.Generic;

namespace Kivensoft.XlsReader {
	public abstract class BaseCells {
		protected IList<Cell> _cells = new List<Cell>();

		public BaseCells(int index) {
			Index = index;
			Hidden = false;
		}

		public BaseCells(int index, bool hidden) {
			Index = index;
			Hidden = hidden;
		}

		public int Index { get; set; }

		public bool Hidden { get; set; }

		public Sheet Sheet { get; set; }

		public IList<Cell> Cells { get { return _cells; } }

		public abstract void AddCell(Cell cell);

		public abstract Cell Cell(int index);

		public string CellAsString(int index) {
			var c = Cell(index);
			return c == null ? null : c.Value;
		}

		public int? CellAsInt(int index) {
			var c = Cell(index);
			return c == null ? null : c.AsInt;
		}

		public double? CellAsDouble(int index) {
			var c = Cell(index);
			return c == null ? null : c.AsDouble;
		}

		public decimal? CellAsDecimal(int index) {
			var c = Cell(index);
			return c == null ? null : c.AsDecimal;
		}

		public DateTime? CellAsDate(int index) {
			var c = Cell(index);
			return c == null ? null : c.AsDate;
		}

		public TimeSpan? CellAsTime(int index) {
			var c = Cell(index);
			return c == null ? null : c.AsTime;
		}

		public DateTime? CellAsDateTime(int index) {
			var c = Cell(index);
			return c == null ? null : c.AsDateTime;
		}
	}
}
